/****************************************************
	文件：ResUtil.cs
	作者：HuskyT
	邮箱：1005240602@qq.com
	日期：2020/12/20 17:22:48
	功能：Res工具类
*****************************************************/

using System;
using HTFW.Consts;
using UnityEngine;

namespace HTFW.Res
{
    public class ResUtil
    {
        #region Public Function

        /// <summary>
        /// 获取指定AB包的完整路径
        /// </summary>
        public static string GetABFullPath(string abName)
        {
            return Application.streamingAssetsPath + "/AssetBundles/" + GetPlatformName() + "/" + abName;
        }

        /// <summary>
        /// 获取当前平台Name
        /// </summary>
        public static string GetPlatformName()
        {
#if UNITY_EDITOR
            return GetPlatformName(UnityEditor.EditorUserBuildSettings.activeBuildTarget);
#else
            return GetPlatformName(Application.platform);
#endif
        }

        /// <summary>
        /// 获取资源全路径（Assets下的路径）
        /// </summary>
        /// <param name="resourceName"></param>
        /// <param name="resourceType"></param>
        /// <returns></returns>
        public static string GetResFullPath(string resourceName, ResourceType resourceType)
        {
            switch (resourceType)
            {
                case ResourceType.UI_Prefab:
                    return $"{ResDefine.PREFIX_PATH_UI_PREFAB}{resourceName}.prefab";
                default:
                    return string.Empty;
            }
        }

        #endregion


        #region Private Function

#if UNITY_EDITOR
        private static string GetPlatformName(UnityEditor.BuildTarget buildTarget)
        {
            switch (buildTarget)
            {
                case UnityEditor.BuildTarget.StandaloneWindows:
                case UnityEditor.BuildTarget.StandaloneWindows64:
                    return HConsts.PlatformName.Windows;
                case UnityEditor.BuildTarget.iOS:
                    return HConsts.PlatformName.Ios;
                case UnityEditor.BuildTarget.Android:
                    return HConsts.PlatformName.Android;
#pragma warning disable 618
                case UnityEditor.BuildTarget.StandaloneLinux:
#pragma warning restore 618
                case UnityEditor.BuildTarget.StandaloneLinux64:
#pragma warning disable 618
                case UnityEditor.BuildTarget.StandaloneLinuxUniversal:
#pragma warning restore 618
                    return HConsts.PlatformName.Linux;
                case UnityEditor.BuildTarget.StandaloneOSX:
                    return HConsts.PlatformName.Osx;
                case UnityEditor.BuildTarget.WebGL:
                    return HConsts.PlatformName.WebGl;
                default:
                    return null;
            }
        }
#endif
        private static string GetPlatformName(RuntimePlatform runtimePlatform)
        {
            switch (runtimePlatform)
            {
                case RuntimePlatform.WindowsPlayer:
                    return HConsts.PlatformName.Windows;
                case RuntimePlatform.IPhonePlayer:
                    return HConsts.PlatformName.Ios;
                case RuntimePlatform.Android:
                    return HConsts.PlatformName.Android;
                case RuntimePlatform.LinuxPlayer:
                    return HConsts.PlatformName.Linux;
                case RuntimePlatform.OSXPlayer:
                    return HConsts.PlatformName.Osx;
                case RuntimePlatform.WebGLPlayer:
                    return HConsts.PlatformName.WebGl;
                default:
                    return null;
            }
        }

        #endregion
    }
}